package ui.faces
{
	import events.GestureEvent;
	
	import global.Managers;
	
	import resources.Resources;
	
	import ui.components.Button;
	import ui.panels.PanelType;
	import ui.recipe.Recipe;
	
	/**
	 *
	 * 点菜界面
	 * @author Raykid
	 * 
	 */	
	public class DiningFace extends AbstractFace
	{
		private var _recipe					: Recipe;
		private var _btnOrdered				: Button;
		private var _btnMain				: Button;
		private var _btnChangeLanguage		: Button;
		
		public function DiningFace()
		{
			super();
		}
		override protected function createBG():void {
			super.createBG();
			_bg.addChild(Managers.resourceManager.getBitmap(Resources.DINING_FACE_BG));
		}
		override protected function createView():void {
			super.createView();
			
			_recipe = new Recipe();
			_recipe.x = 112;
			_recipe.y = 34;
			addChild(_recipe);
			
			_btnOrdered = new Button(0, _languageManager.getLanguageText("ordered"), 150, 40, "", function(event:GestureEvent):void {
				Managers.panelManager.open(PanelType.ORDERED_DISH);
			});
			_btnOrdered.x = 850;
			_btnOrdered.y = 600;
			addChild(_btnOrdered);
			_btnOrdered.addListener(this);
			
			_btnMain = new Button(0, "", 150, 40, "", function(event:GestureEvent):void {
				Managers.faceManager.switchTo(Managers.faceManager.mainFace);
			});
			_btnMain.text = _languageManager.getLanguageText("home_page");
			_btnMain.x = 850;
			_btnMain.y = 720;
			addChild(_btnMain);
			_btnMain.addListener(this);
			
			_btnChangeLanguage = new Button(1, "", 150, 40, "", function(event:GestureEvent):void {
				_languageManager.currentLanguage = 3 - _languageManager.currentLanguage;
			});
			_btnChangeLanguage.text = _languageManager.getLanguageText("translate");
			_btnChangeLanguage.x = 850;
			_btnChangeLanguage.y = 660;
			addChild(_btnChangeLanguage);
			_btnChangeLanguage.addListener(this);
		}
		
		public function updateRecipe():void {
			_recipe.reset();
			_recipe.update(Managers.dishManager.dishes, Managers.layoutManager.layoutVO);
		}
		override public function switchLanguage(toLanguage:int):void {
			super.switchLanguage(toLanguage);
			
			if(toLanguage == _currentLanguage) return;
			_currentLanguage = toLanguage;
			
			updateRecipe();
			_btnOrdered.text = _languageManager.getLanguageText("ordered");
			_btnMain.text = _languageManager.getLanguageText("home_page");
			_btnChangeLanguage.text = _languageManager.getLanguageText("translate");
		}
		override public function reset():void {
			super.reset();
			
			Managers.layoutManager.getLayout();
		}
	}
}